package com.riko.comic.core.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 角色拦截器
 *
 * @author riko
 * @since 2021/10/29
 */
public class RoleInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String username = (String)request.getSession().getAttribute("username");

        if (username.equals("admin")) {
            return true;
        } else {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write("<h1>权限不足<h1>");
        }

        return false;
    }
}
